cmake_minimum_required(VERSION 3.10)
project(SimpleSemantic)

set(CMAKE_CXX_STANDARD 14)

# Current version
set(SIMPLE_SEMANTIC_VERSION_MAJOR 0)
set(SIMPLE_SEMANTIC_VERSION_MINOR 1)
set(SIMPLE_SEMANTIC_VERSION_PATCH 0)
# Converts the version number to a string
string(CONCAT SIMPLE_SEMANTIC_VERSION_MAJOR_STR ${SIMPLE_SEMANTIC_VERSION_MAJOR})
string(CONCAT SIMPLE_SEMANTIC_VERSION_MINOR_STR ${SIMPLE_SEMANTIC_VERSION_MINOR})
string(CONCAT SIMPLE_SEMANTIC_VERSION_PATCH_STR ${SIMPLE_SEMANTIC_VERSION_PATCH})
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/version.h.in ${CMAKE_CURRENT_SOURCE_DIR}/src/version.h)

if (APPLE)
    set(PLATFORM Darwin)
elseif(ANDROID)
    set(PLATFORM Android)
endif ()

set(NEED_LINKE "")
set(NEED_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/src/")


file(GLOB_RECURSE CLASSIFY_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/semantic_classify/*.cpp)
file(GLOB ROOT_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
set(SOURCE_FILES ${CLASSIFY_FILES} ${ROOT_FILES})

# FastText
if (NOT ANDROID)
    set(FASTTEXT_LIB "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/FastText/${PLATFORM}/libfasttext.a")
    set(NEED_LINKE ${NEED_LINKE} ${FASTTEXT_LIB})
else()
    set(SOURCE_FILES ${SOURCE_FILES} "${CMAKE_CURRENT_SOURCE_DIR}/src/platform/android/native_interface.cpp")

    link_directories(${FASTTEXT_LIB})
    set(NEED_LINKE ${NEED_LINKE} fasttext)
endif ()
set(FASTTEXT_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/FastText/include")
message(STATUS FastText="${FASTTEXT_LIB}")

set(NEED_INCLUDE ${NEED_INCLUDE} ${FASTTEXT_INCLUDE})

# Limonp
set(LIMONP_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/limonp")
set(NEED_INCLUDE ${NEED_INCLUDE} ${LIMONP_INCLUDE})

# CPPJieba
set(JIEBA_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/jieba/include")
set(NEED_INCLUDE ${NEED_INCLUDE} ${JIEBA_INCLUDE})

# Include
include_directories(${NEED_INCLUDE})

if(NOT ANDROID)
    # Add Exec
    add_executable(SimpleSemantic sample/main.cpp)
    add_executable(JiebaDemo sample/jieba_demo.cpp)
    add_executable(OLDemo sample/ol_demo.cpp)

    add_executable(RunSample sample/run_sample.cpp ${SOURCE_FILES})

    add_executable(Train sample/train.cpp ${SOURCE_FILES})

    add_executable(RunPredictor sample/run_predictor.cpp ${SOURCE_FILES})

    add_executable(TextProcessSample sample/text_process_sample.cpp ${SOURCE_FILES})

    # Linked
    target_link_libraries(SimpleSemantic ${NEED_LINKE})

    target_link_libraries(JiebaDemo ${NEED_LINKE})

    target_link_libraries(RunSample ${NEED_LINKE})

    target_link_libraries(Train ${NEED_LINKE})

    target_link_libraries(RunPredictor ${NEED_LINKE})

    target_link_libraries(TextProcessSample ${NEED_LINKE})

else()
    add_library(simplesemantic SHARED ${SOURCE_FILES})
    set_target_properties(simplesemantic PROPERTIES
            VERSION ${SIMPLE_SEMANTIC_VERSION_MAJOR}.${SIMPLE_SEMANTIC_VERSION_MINOR}.${SIMPLE_SEMANTIC_VERSION_PATCH}
            SOVERSION ${SIMPLE_SEMANTIC_VERSION_MAJOR}
            )
    message(NEED_LINKE=${NEED_LINKE})
    target_link_libraries(simplesemantic log ${NEED_LINKE})

endif()
